import axios from "axios";
const requestAi = axios.create({
    baseURL: import.meta.env.VITE_AI_DIALOG_URL,
    timeout: 60 * 1000,
    responseType: "json",
    headers: {},
});

requestAi.interceptors.request.use(
    (config) => {
        // const access_token = localStorage.getItem("access_token");

        // if (access_token) {
        //     config.headers.Authorization = "Bearer " + access_token;
        // }

        return config;
    },
    (error) => {
        return Promise.reject(new Error(error));
    }
);

requestAi.interceptors.response.use(
    async (response) => {
        console.log(response);
        return response.data;
    },
    (error) => {
        
        return Promise.reject(error);
    }
);

const fileRequest = axios.create({
    timeout: 30 * 1000,
    responseType: "json",
    headers: { "Content-Type": "multipart/form-data" },
});

fileRequest.interceptors.request.use(
    (config) => {
        return config;
    },
    (error) => {
        return Promise.reject(new Error(error));
    }
);

fileRequest.interceptors.response.use(
    (response) => {
        const status = response.data.code; //获取响应状态码
        //根据接口还可以获取一些其他内容

        //根据不同的状态码作处理
        switch (status) {
            default: //其他状态码
                break;
        }
        return response.data;
    },
    (error) => {
        return Promise.reject(new Error(error));
    }
);

export { requestAi, fileRequest };
